<!--搜索链接-->
<script setup>
import {useStore} from "vuex";
import {ForumType} from "@ginstone/nga-api/dist/src/enums/ForumType";
import NgaRouterLink from "@/components/common/link/NgaRouterLink.vue";
import {routeNames} from "@/router";

const props = defineProps({
  bracket: Boolean,
  // 关键字
  keyword: {type: String, required: true},
  //版面还是合集
  type: {type: String, required: true, validator: (value) => [ForumType.FORUM, ForumType.COLLECTION].includes(value)},
  // 版面或合集的id
  targetId: {type: Number, required: true},
  // 页码
  page: {type: Number},
  // 是否搜索正文
  content: {type: Number | String},
  // 仅搜索精华
  recommend: {type: Number | String},
})
const store = useStore();

// 生成路由
const getRoute = (type, keyword, targetId, page, content, recommend) => {
  //路由名称
  const name = type === ForumType.FORUM ? routeNames.thread.forumSearch : routeNames.thread.colSearch;
  const id = targetId;
  content = content ? 1 : undefined
  recommend = recommend ? 1 : undefined

  return {
    name,
    params: {
      id, keyword,
    },
    query: {
      page, content, recommend
    }
  }
}

</script>

<template>
  <nga-router-link :bracket="bracket" :route="getRoute(type,keyword,targetId,page,content,recommend)">
    <slot></slot>
  </nga-router-link>
</template>

<style scoped>

</style>